package com.ruoyi.web.controller.tools;

import java.util.List;

import com.ruoyi.system.domain.SysOrdersTools;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTools;
import com.ruoyi.system.service.ISysToolsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工具管理Controller
 *
 * @author ruoyi
 * @date 2021-10-26
 */
@RestController
@RequestMapping("/system/tools")
public class SysToolsController extends BaseController
{
    @Autowired
    private ISysToolsService sysToolsService;

    /**
     * 查询工具管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:tools:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTools sysTools)
    {
        startPage();
        List<SysTools> list = sysToolsService.selectSysToolsList(sysTools);
        return getDataTable(list);
    }

    /**
     * 导出工具管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:tools:export')")
    @Log(title = "工具管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysTools sysTools)
    {
        List<SysTools> list = sysToolsService.selectSysToolsList(sysTools);
        ExcelUtil<SysTools> util = new ExcelUtil<SysTools>(SysTools.class);
        return util.exportExcel(list, "工具管理数据");
    }

    /**
     * 获取工具管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tools:query')")
    @GetMapping(value = "/{toolId}")
    public AjaxResult getInfo(@PathVariable("toolId") Integer toolId)
    {
        return AjaxResult.success(sysToolsService.selectSysToolsByToolId(toolId));
    }

    /**
     * 新增工具管理
     */
    @PreAuthorize("@ss.hasPermi('system:tools:add')")
    @Log(title = "工具管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTools sysTools)
    {
        return toAjax(sysToolsService.insertSysTools(sysTools));
    }

    /**
     * 修改工具管理
     */
    @PreAuthorize("@ss.hasPermi('system:tools:edit')")
    @Log(title = "工具管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTools sysTools)
    {
        return toAjax(sysToolsService.updateSysTools(sysTools));
    }

    /**
     * 删除工具管理
     */
    @PreAuthorize("@ss.hasPermi('system:tools:remove')")
    @Log(title = "工具管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{toolIds}")
    public AjaxResult remove(@PathVariable Integer[] toolIds)
    {
        return toAjax(sysToolsService.deleteSysToolsByToolIds(toolIds));
    }
//获取全部维修工具
    @GetMapping("/alltools")
    @ResponseBody
    public List<SysTools> getAlltools(SysTools sysTools ){
        return sysToolsService.selectSysToolsList(sysTools);

    }
}